const app = getApp();
Page({
  data:{
    resourceDomain: app.resourceDomain
  },
  onLoad: function (options) {

    var that = this;
    /**
     * 积分明细接口
     * type=2 为支出项
     */
    app.request(app.apiDomain + 'index.php?c=user&a=dailys', {
			user_id:options.user_id
		}, function (res) {
      if (res.data.status == '1') {
        that.setData({
          dailys: res.data.data
        });
      }
    });
  },
  likesubmit: function (e) {
    console.log(e.detail);
    var id = e.detail.target.dataset.id;
    var action = e.detail.target.dataset.action;
    if (action == 'like') {
      this.like(id, e.detail.formId);
    } else {
      this.unlike(id, e.detail.formId);
    }
  },
  like: function (id, form_id) {
    var that = this;
    app.request(app.apiDomain + 'index.php?c=user&a=like', {
			type:'daily',
			id:id,
			form_id:form_id
		}, function (res) {
      if (res.data.status == '1') {
        that.setData({
          reward_like: 1,
          reward_like_num: res.data.data.like_num,
        });
      }
    });
  },
  unlike: function (id, form_id) {
    var that = this;
    app.request(app.apiDomain + 'index.php?c=user&a=unlike', {
			type:'daily',
			id:id,
			form_id:form_id
		}, function (res) {
      if (res.data.status == '1') {
        that.setData({
          reward_like: 0,
          reward_like_num: res.data.data.like_num,
        });
      }
    });
  }, 
  onShareAppMessage: function () {
    return app.onShareAppMessage();
  }  
})



